﻿namespace SingletonPattern
{
    /// <summary>
    /// 延迟初始化
    /// </summary>
    public class NestedSingleton
    {
        NestedSingleton() { }

        public static NestedSingleton Instance
        {
            get
            {
                // only when thread call the property then it will call the nested class to get the init field
                return NestedClass.instance;
            }
        }

        class NestedClass
        {
            NestedClass() { }

            internal static readonly NestedSingleton instance = new NestedSingleton();
        }
    }
}